///////////////////////////////////////////////////////////////////////////////
///                                                                         ///
/// <cwmp.h> - CWMP - TR069 common module.                                  ///
///                                                                         ///
/// Version :        0.0.2                                                  ///
/// Language :       C                                                      ///
/// Platform :       Linux                                                  ///
/// Application :    TR069                                                  ///
/// Author :         Ireta                                                  ///
/// Created Date :   2012_07_01                                             ///
/// Header :                                                                ///
///                                                                         ///
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
///                           Maintenance                                   ///
///////////////////////////////////////////////////////////////////////////////

/*
 Version  Modified By  Date        Remarks
 =============================================================================
 0.0.1    Ireta        2012-07-01  Basic initiate
 0.0.2    Ireta        2014-10-03  Refine ramdisk path.
 */

#ifndef CWMP_H
#define CWMP_H

///////////////////////////////////////////////////////////////////////////////
///                           Headers                                       ///
///////////////////////////////////////////////////////////////////////////////
#include <stdbool.h>

#include "libctools/common.h"
#include "libctools/list_utils.h"

# ifdef __cplusplus
extern "C" {
# endif

///////////////////////////////////////////////////////////////////////////////
///                      Data Structure Declarations                        ///
///////////////////////////////////////////////////////////////////////////////
// for compiling by eclipse
#define SENSOR_GW
#define CPE_TEST 0

#ifdef WIN32
#define PATH_SEP                    "\\"
#else
#define PATH_SEP                    "/"
#endif

#define DIRPATH_PROFILE             "Profiles"
#define DIRPATH_PROFILE_BACKUP      "Profiles"PATH_SEP"Backup"
#define DIRPATH_PROFILE_TEMPLATE    "Profiles"PATH_SEP"Template"
#define DIRPATH_PROFILE_FACTORY     "Profiles"PATH_SEP"Factory"

#define DIRPATH_RAMDISK             "ramdisk"

#ifdef ANDROID
#define DIRPATH_DOWNLOAD            "/sdcard/tr069/download"
#define DIRPATH_UPLOAD              "/sdcard/tr069/upload"
#else
#define DIRPATH_DOWNLOAD            "download"
#define DIRPATH_UPLOAD              "upload"
#endif

#define TR098_ROOT_NAME             "InternetGatewayDevice"
#define TR106_ROOT_NAME             "Device"

#define HTTP_POST_NORMAL_SIZE       6000
#define HTTP_POST_MAX_SIZE          200000 //50000; if this number is too small, cause 9004(RESOURCES EXCEEDED) fault code easily.
#define CWMP_REQ_ID_LENGTH          STRING_MIN_LENGTH
#define CWMP_PARAM_LENGTH           STRING_MID_LENGTH
#define CWMP_NAME_LENGTH            STRING_MID_LENGTH
//#define CWMP_VALUE_LENGTH 		STRING_MID_LENGTH
#define CWMP_VALUE_LENGTH           10000 // Temperary Change. Ireta 2014/04/23
#define CWMP_TYPE_LENGTH            STRING_MIN_LENGTH
#define CWMP_LIST_LENGTH            STRING_MAX_LENGTH
#define CWMP_RELATE_LENGTH          STRING_MAX_LENGTH
#define CWMP_DATETIME_LENGTH        STRING_MIN2_LENGTH
#define CWMP_CMDKEY_LENGTH          STRING_MIN_LENGTH
#define CWMP_FILETYPE_LENGTH        STRING_MIN_LENGTH
#define CWMP_URL_LENGTH             STRING_MID_LENGTH
#define CWMP_4URL_LENGTH            STRING_MAX_LENGTH
#define CWMP_USERNAME_LENGTH        STRING_MID_LENGTH
#define CWMP_PASSWD_LENGTH          STRING_MID_LENGTH
#define CWMP_FILENAME_LENGTH        STRING_MID_LENGTH
#define CWMP_FILESIZE_LENGTH        STRING_MIN2_LENGTH
#define CWMP_FAULTCODE_LENGTH       STRING_MIN2_LENGTH
#define CWMP_FAULTSTR_LENGTH        STRING_MID_LENGTH

#define PARAMETER_VALUE_FROM_PROFILE 1
#define PARAMETER_VALUE_FROM_DAEMON  3

typedef struct ParameterValue {
	char name[CWMP_NAME_LENGTH];
	char value[CWMP_VALUE_LENGTH]; // Note: some Value more than 256, maybe cause an error;
								   // the maximum string length of some parameters are 61430.
	char type[CWMP_TYPE_LENGTH];   // In TR-069 Spec. Table 9 - Data types;
	int  notification;             // 0 ~ 3

    int  flag; // 0: initial value, 1: done with value from profile, 3: done with value from daemon, -1: error
} ParameterValue;

typedef struct ParameterInfo {
	char name[CWMP_NAME_LENGTH];
	bool writable;
} ParameterInfo;

typedef struct ParameterAttribute {
	char name[CWMP_NAME_LENGTH];
	bool notificationChange;
	int notification;
	bool accessListChange;
	List accessList;

	int flag; // 0: init, 1: done, -1: error
} ParameterAttribute;

typedef struct AddDeleteObject {
	char objectName[CWMP_NAME_LENGTH];
	int instanceNumber;
	int flag; // 0: init, 1: done, -1: error
} AddDeleteObject;

/*
 * CPE Fault Code Enumeration
 */
enum CpeFaultCode_e {
	CPE_NO_FAULT = 0,
	CPE_METHOD_NOT_SUPPORTED = 9000,
	CPE_REQUEST_DENIED = 9001,
	CPE_INTERNAL_ERROR = 9002,
	CPE_INVALID_ARGUMENTS = 9003,
	CPE_RESOURCES_EXCEEDED = 9004,
	CPE_INVALID_PARAMETER_NAME = 9005,
	CPE_INVALID_PARAMETER_TYPE = 9006,
	CPE_INVALID_PARAMETER_VALUE = 9007,
	CPE_NON_WRITABLE_PARAMETER = 9008,
	CPE_NOTIFICATION_REQUEST_REJECTED = 9009,
	CPE_DOWNLOAD_FAILURE = 9010,
	CPE_UPLOAD_FAILURE = 9011,
	CPE_FILE_TRANSFER_SERVER_AUTH_FAILURE = 9012,
	CPE_UNSUPPORTED_PROTOCOL_FILE_TRANSFER = 9013,
	CPE_DOWNLOAD_FAILURE_UNABLE_TO_JOIN_MULTICAST_GROUP = 9014,
	CPE_DOWNLOAD_FAILURE_UNABLE_TO_CONTACT_FILE_SERVER = 9015,
	CPE_DOWNLOAD_FAILURE_UNABLE_TO_ACCESS_FILE = 9016,
	CPE_DOWNLOAD_FAILURE_UNABLE_TO_COMPLETE_DOWNLOAD = 9017,
	CPE_DOWNLOAD_FAILURE_FILE_CORRUPTED = 9018,
	CPE_DOWNLOAD_FAILURE_FILE_AUTH_FAILURE = 9019,
};

/*
 * ACS Fault Code Enumeration
 */
enum AcsFaultCode_e {
	ACS_NO_FAULT = 0,
	ACS_METHOD_NOT_SUPPORTED = 8000,
	ACS_REQUEST_DENIED = 8001,
	ACS_INTERNAL_ERROR = 8002,
	ACS_INVALID_ARGUMENTS = 8003,
	ACS_RESOURCES_EXCEEDED = 8004,
	ACS_RETRY_REQUEST = 8005,
};

typedef struct SetParameterValueFault_s {
	char name[CWMP_NAME_LENGTH];
	int faultCode;
} SetParameterValueFault_t;

// add by jcwang_20121212
enum DM_REPORT_MSG {
	MSG_GET_PARAMETER_VALUES_RESPONSE,
	MSG_SET_PARAMETER_VALUES_RESPONSE,
	MSG_ADD_OBJECT_RESPONSE,
	MSG_DELETE_OBJECT_RESPONSE,
	MSG_DIAGNOSTICS_COMPLETE
};

enum DATACMD {
	DATACMD_INIT = 0,
	DATACMD_GET,
	DATACMD_SET,
	DATACMD_NOTIFICATION,
};

#define RESOURCE_EXCEEDED_THRESHOLD   100

///////////////////////////////////////////////////////////////////////////////
///                   Public Interface Declarations                         ///
///////////////////////////////////////////////////////////////////////////////

enum CWMP_PROFILE_OPERATION {
	ProfileOperation_Add,
	ProfileOperation_Update,
	ProfileOperation_Delete,
	ProfileOperation_Enable,
	ProfileOperation_Disable,
	ProfileOperation_None
};

# ifdef __cplusplus
}
#endif

#endif // CWMP_H
